<?php
/*
	Copyright 2006, 2007, 2008, 2009, 2010 Bastiaan Grutters
    
    This file is part of Ages of Strife website.

    Ages of Strife website is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Ages of Strife website is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Ages of Strife website.  If not, see <http://www.gnu.org/licenses/>.
 */
include( '../global/initialize.php' );

include( "../global/JSON.php" );

$tab = $_GET[ 'tab' ];
$json = new Services_JSON();
$response = Array();
$style->background->color = '0xCCAC5E';
$style->yAxis->titleRotation = -90;
$style->secundaryYAxis->titleRotation = 90;
if( $tab == 'overview' ) {
	$query = "SELECT * " .
			"FROM ruler " .
			"WHERE ruler_id = " . $_SESSION[ 'ruler_id' ];
	$result = mysql_query( $query ) or die( "Query failed : " . mysql_error() );
	$row = mysql_fetch_array($result, MYSQL_ASSOC);
	$score = $row[ 'score' ];
	$query = "SELECT count(*) " .
			"FROM ruler " .
			"WHERE score > $score";
	$result = mysql_query( $query ) or die( "Query failed : " . mysql_error() );
	$row = mysql_fetch_array($result, MYSQL_ASSOC);
	$rank = $row[ 'count(*)' ];
	
	$rank -= 4;
	if( $rank < 0 ) {
		$rank = 0;
	}
	
	$query = "SELECT * " .
			"FROM ruler " .
			"ORDER BY score DESC " .
			"LIMIT $rank, 8";
	$result = mysql_query( $query ) or die( "Query failed : " . mysql_error() );
	$num = mysql_numrows( $result );
	$i = 0;
	$response[0] = new StdClass();
	$response[0]->title = "Rulers";
	$response[0]->data = Array();
	while ( $i < $num ) {
		$query2 = "SELECT count(*) " .
				"FROM ruler " .
				"WHERE score > " . mysql_result( $result, $i, "score" );
		$result2 = mysql_query( $query2 ) or die( "Query failed : " . mysql_error() );
		$row2 = mysql_fetch_array( $result2, MYSQL_ASSOC );
		$count_rank = $row2[ 'count(*)' ] + 1;
		
		$data = new stdClass();
		$data->name = $count_rank . ". " . mysql_result( $result, $i, "name" );
		$data->score = mysql_result( $result, $i, "score" );
		$data->experience = mysql_result( $result, $i, "experience" );
		$response[0]->data[] = $data;
		$i ++;
	}
	$response[0]->responseSchema->fields = Array( 'name', 'score', 'experience' );
	$options = new stdClass();
	$options->series = Array();
	$series = new stdClass();
	$series->yField = 'score';
	$series->displayName = 'Score';
	$series->style->color = '0x0F780F';
	$series->style->size = 10;
	$options->series[] = $series;
	$series = new stdClass();
	$series->yField = 'experience';
	$series->displayName = 'Battle score';
	$series->style->color = '0xC83C28';
	$series->style->size = 10;
	$options->series[] = $series;
	
	$options->xField = 'name';
	$options->yAxis = "numberAxis";
	$options->dataTipFunction = "getDataTipTextColumn";
	$options->expressInstall = "assets/expressinstall.swf";
	$options->style = $style; 
	$response[0]->options = $options;
	$response[0]->chartType = 'column';
	
	$response[1] = new StdClass();
	$response[1]->title = "Progress";
	$response[1]->data = Array();
	$query = "SELECT `value`, `type`, `description`, `turn` " .
			"FROM premium_stats " .
			"WHERE ruler_id = " . $_SESSION[ 'ruler_id' ] . ' AND ' .
					'( `type` = 1 OR `type` = 2 OR `type` = 3 OR `type` = 4 OR `type` = 5 OR `type` = 6 OR `type` = 9 OR `type` = 10 ) ' .
			'ORDER BY turn ASC, type ASC';
	$result = mysql_query( $query ) or die( "Query failed : " . mysql_error() );
	$num = mysql_numrows( $result );
	$i = 0;
	$lastTurn = -1;
	while ( $i < $num ) {
		if( $lastTurn != mysql_result( $result, $i, 'turn' ) || $lastTurn == -1 ) {
			if( $lastTurn != -1 ) {
				$response[1]->data[] = $data;
			}
			$data = new stdClass();
			$data->turn = $lastTurn = mysql_result( $result, $i, 'turn' );
		}
		//$data->name = translate( mysql_result( $result, $i, 'description' ) ) . ' ' . number_format( mysql_result( $result, $i, 'vale' ) );
		if( mysql_result( $result, $i, 'type' ) == 1 ) {
			$data->score = mysql_result( $result, $i, 'value' );
		}
		elseif( mysql_result( $result, $i, 'type' ) == 2 ) {
			$data->battle_score = mysql_result( $result, $i, 'value' );
		}
		elseif( mysql_result( $result, $i, 'type' ) == 3 ) {
			$data->resource_score = mysql_result( $result, $i, 'value' );
		}
		elseif( mysql_result( $result, $i, 'type' ) == 4 ) {
			$data->army_score = mysql_result( $result, $i, 'value' );
		}
		elseif( mysql_result( $result, $i, 'type' ) == 5 ) {
			$data->rank = mysql_result( $result, $i, 'value' );
		}
		elseif( mysql_result( $result, $i, 'type' ) == 6 ) {
			$data->battle_rank = mysql_result( $result, $i, 'value' );
		}
		elseif( mysql_result( $result, $i, 'type' ) == 9 ) {
			$data->economy_rank = mysql_result( $result, $i, 'value' );
		}
		elseif( mysql_result( $result, $i, 'type' ) == 10 ) {
			$data->war_rank = mysql_result( $result, $i, 'value' );
		}
		$i ++;
	}
	if( $lastTurn != -1 ) {
		$response[1]->data[] = $data;
	}
	$response[1]->responseSchema->fields = Array( 'turn', 'score', 'battle_score', 'resource_score', 'army_score', 'rank', 'battle_rank', 'economy_rank', 'war_rank' );

	$options = new stdClass();
	$options->series = Array();
	$series = new stdClass();
	$series->yField = 'score';
	$series->axis = 'primary';
	$series->displayName = 'Score';
	$series->style = new stdClass();
	$series->style->color = '0x0F780F';
	$series->style->size = 6;
	$options->series[] = $series;
	$series = new stdClass();
	$series->yField = 'battle_score';
	$series->axis = 'primary';
	$series->displayName = 'Battle score';
	$series->style = new stdClass();
	$series->style->color = '0xC83C28';
	$series->style->size = 6;
	$options->series[] = $series;
	$series = new stdClass();
	$series->yField = 'resource_score';
	$series->axis = 'primary';
	$series->displayName = 'Resource score';
	$series->style = new stdClass();
	$series->style->color = '0x5f5500';
	$series->style->size = 6;
	$options->series[] = $series;
	$series = new stdClass();
	$series->yField = 'army_score';
	$series->axis = 'primary';
	$series->displayName = 'Army score';
	$series->style = new stdClass();
	$series->style->color = '0x3700a7';
	$series->style->size = 6;
	$options->series[] = $series;
	$series = new stdClass();
	$series->yField = 'rank';
	$series->axis = 'secondary';
	$series->displayName = 'Rank';
	$series->style = new stdClass();
	$series->style->color = '0x0F780F';
	$series->style->size = 3;
	$options->series[] = $series;
	$series = new stdClass();
	$series->yField = 'battle_rank';
	$series->axis = 'secondary';
	$series->displayName = 'Battle rank';
	$series->style = new stdClass();
	$series->style->color = '0xC83C28';
	$series->style->size = 3;
	$options->series[] = $series;
	$series = new stdClass();
	$series->yField = 'economy_rank';
	$series->axis = 'secondary';
	$series->displayName = 'Economy rank';
	$series->style = new stdClass();
	$series->style->color = '0x2F982F';
	$series->style->size = 3;
	$options->series[] = $series;
	$series = new stdClass();
	$series->yField = 'war_rank';
	$series->axis = 'secondary';
	$series->displayName = 'War rank';
	$series->style = new stdClass();
	$series->style->color = '0xE85C48';
	$series->style->size = 3;
	$options->series[] = $series;
	
	$statement = $dal->prepare( 'SELECT count(*) ' .
			'FROM ruler' );
	
	$options->xField = 'turn';
	$options->yAxis = "numberAxis";
	$options->yAxisTitle = "Points";
	$options->rightYAxis = "numberAxis";
	$options->rightYTitle = "Rank";
	$options->rightMaximum = $dal->getValue( $statement );
	$options->dataTipFunction = "getDataTipTextColumn";
	$options->expressInstall = "assets/expressinstall.swf";
	$options->style = $style; 
	$response[1]->options = $options;
	$response[1]->chartType = 'line';
	
}
elseif( $tab == 'villages' ) {
	$query = "SELECT * " .
			"FROM village " .
			"WHERE ruler_id = " . $_SESSION[ 'ruler_id' ] .
			" ORDER BY ( food_income + iron_income * 6 + coal_income * 4 ) DESC " .
			"LIMIT 8";
			
	$result = mysql_query( $query ) or die( "Query failed : " . mysql_error() );
	$num = mysql_numrows( $result );
	$i = 0;
	$response[0] = new StdClass();
	$response[0]->title = "Villages (by productivity)";
	$response[0]->data = Array();
	while ( $i < $num ) {
		$data = new stdClass();
		$data->name = mysql_result( $result, $i, "name" );
		$data->population = mysql_result( $result, $i, "population" ) / 10;
		$data->food_income = mysql_result( $result, $i, "food_income" );
		$data->iron_income = mysql_result( $result, $i, "iron_income" );
		$data->coal_income = mysql_result( $result, $i, "coal_income" );
		$response[0]->data[] = $data;
		$i ++;
	}
	$response[0]->responseSchema->fields = Array( 'name', 'population', 'food_income', 'iron_income', 'coal_income' );
	$options->series = Array();
	$series = new stdClass();
	$series->yField = 'population';
	$series->displayName = 'Population (1/10th)';
	$series->style->color = '0xDEDEDE';
	$series->style->size = 10;
	$options->series[] = $series;
	$series = new stdClass();
	$series->yField = 'food_income';
	$series->displayName = 'Food income';
	$series->style->color = '0x0F780F';
	$series->style->size = 10;
	$options->series[] = $series;
	$series = new stdClass();
	$series->yField = 'iron_income';
	$series->displayName = 'Iron income';
	$series->style->color = '0xC83C28';
	$series->style->size = 10;
	$options->series[] = $series;
	$series = new stdClass();
	$series->yField = 'coal_income';
	$series->displayName = 'Coal income';
	$series->style->color = '0x2D2D2D';
	$series->style->size = 10;
	$options->series[] = $series;
	
	$options->xField = 'name';
	$options->yAxis = "numberAxis";
	$options->dataTipFunction = "getDataTipTextColumn";
	$options->expressInstall = "assets/expressinstall.swf";
	$options->style = $style; 
	$response[0]->options = $options;
	$response[0]->chartType = 'column'; 	

}
elseif( $tab == 'operations' ) {
//	$query = "SELECT scouts, infantry, cavalry, artillery " .
//			"FROM ruler " .
//			"WHERE ruler_id = " . $_SESSION[ 'ruler_id' ];
//	$result = mysql_query( $query ) or die( "Query failed : " . mysql_error() );
//	$row = mysql_fetch_array($result, MYSQL_ASSOC);
//	$scouts = $row[ 'scouts' ];
//	$infantry = $row[ 'infantry' ];
//	$cavalry = $row[ 'cavalry' ];
//	$artillery = $row[ 'artillery' ];
//	
//	$query = "SELECT SUM( scout ), SUM( infantry ), SUM( cavalry ), SUM( artillery ) " .
//			"FROM army " .
//			"WHERE ruler_id = " . $_SESSION[ 'ruler_id' ];
//	$result = mysql_query( $query ) or die( "Query failed : " . mysql_error() );
//	$row = mysql_fetch_array($result, MYSQL_ASSOC);
//	$scouts += $row[ 'SUM( scout )' ];
//	$infantry += $row[ 'SUM( infantry )' ];
//	$cavalry += $row[ 'SUM( cavalry )' ];
//	$artillery += $row[ 'SUM( artillery )' ];
//	
//	$query = "SELECT SUM( scouts ), SUM( infantry ), SUM( cavalry ), SUM( artillery ) " .
//			"FROM transfer " .
//			"WHERE ruler_id = " . $_SESSION[ 'ruler_id' ];
//	$result = mysql_query( $query ) or die( "Query failed : " . mysql_error() );
//	$row = mysql_fetch_array($result, MYSQL_ASSOC);
//	$scouts += $row[ 'SUM( scouts )' ];
//	$infantry += $row[ 'SUM( infantry )' ];
//	$cavalry += $row[ 'SUM( cavalry )' ];
//	$artillery += $row[ 'SUM( artillery )' ];
//	
//	$response[0] = new stdClass();
//	$response[0]->title = "Our militaries composition";
//	$response[0]->data = Array();
//	$scouts_data->total = $scouts;
//	$scouts_data->name = "Scouts";
//	$response[0]->data[] = $scouts_data;
//	$infantry_data->total = $infantry;
//	$infantry_data->name = "Infantry";
//	$response[0]->data[] = $infantry_data;
//	$cavalry_data->total = $cavalry;
//	$cavalry_data->name = "Cavalry";
//	$response[0]->data[] = $cavalry_data;
//	$artillery_data->total = $artillery;
//	$artillery_data->name = "Artillery";
//	$response[0]->data[] = $artillery_data;
//	
//	$response[0]->responseSchema = new stdClass();
//	$response[0]->responseSchema->fields = Array( 'name', 'total' );
//	$options = new stdClass();
//	$options->dataField = 'total';
//	$options->categoryField = 'name';
//	$options->series = Array();
//	$options->expressInstall = "assets/expressinstall.swf";
//	$options->style = $style; 
//	$options->dataTipFunction = "getDataTipTextPie";
//	$response[0]->options = $options;
//	$response[0]->chartType = 'pie'; 
	
	$query = "SELECT scouts_killed, infantry_killed, cavalry_killed, artillery_killed, scouts_lost, infantry_lost, cavalry_lost, artillery_lost " .
			"FROM ruler " .
			"WHERE ruler_id = " . $_SESSION[ 'ruler_id' ];
	$result = mysql_query( $query ) or die( "Query failed : " . mysql_error() );
	$row = mysql_fetch_array($result, MYSQL_ASSOC);

	$response[1] = new stdClass();
	$response[1]->title = "Our kills and losses";
	$response[1]->data = Array();
	$scouts_data = new stdClass();
	$scouts_data->killed = $row[ 'scouts_killed' ];
	$scouts_data->lost = $row[ 'scouts_lost' ];
	$scouts_data->name = "Scouts";
	$response[1]->data[] = $scouts_data;
	$infantry_data = new stdClass();
	$infantry_data->killed = $row[ 'infantry_killed' ];
	$infantry_data->lost = $row[ 'infantry_lost' ];
	$infantry_data->name = "Infantry";
	$response[1]->data[] = $infantry_data;
	$cavalry_data = new stdClass();
	$cavalry_data->killed = $row[ 'cavalry_killed' ];
	$cavalry_data->lost = $row[ 'cavalry_lost' ];
	$cavalry_data->name = "Cavalry";
	$response[1]->data[] = $cavalry_data;
	$artillery_data = new stdClass();
	$artillery_data->killed = $row[ 'artillery_killed' ];
	$artillery_data->lost = $row[ 'artillery_lost' ];
	$artillery_data->name = "Artillery";
	$response[1]->data[] = $artillery_data;
	$score_killed = $row[ 'scouts_killed' ] * 14 + $row[ 'infantry_killed' ] * 48 + $row[ 'cavalry_killed' ] * 256 + $row[ 'artillery_killed' ] * 400;
	$score_lost = $row[ 'scouts_lost' ] * 14 + $row[ 'infantry_lost' ] * 48 + $row[ 'cavalry_lost' ] * 256 + $row[ 'artillery_lost' ] * 400;
	$score_data = new stdClass();
	$score_data->lost = round( $score_lost * 0.001 );
	$score_data->killed = round( $score_killed * 0.001 );
	$score_data->name = "Score (1/1000th)";
	$response[1]->data[] = $score_data;
	
	$response[1]->responseSchema = new stdClass();
	$response[1]->responseSchema->fields = Array( 'name', 'killed', 'lost' );
	$options = new stdClass();
	$options->series = Array();
	$series = new stdClass();
	$series->yField = 'killed';
	$series->displayName = 'Killed';
	$series->style->color = '0x007700';
	$series->style->size = 20;
	$options->series[] = $series;
	$series = new stdClass();
	$series->yField = 'lost';
	$series->displayName = 'Lost';
	$series->style->color = '0x770000';
	$series->style->size = 20;
	$options->series[] = $series;
	
	$options->xField = 'name';
	$options->yAxis = "numberAxis";
	$options->dataTipFunction = "getDataTipTextColumn";
	//$options->categoryField = 'name';
	//$options->series = Array();
	$options->expressInstall = "assets/expressinstall.swf";
	$options->style = $style; 
	$response[1]->options = $options;
	$response[1]->chartType = 'column'; 	
}
elseif( $tab == 'diplomacy' ) {
	$query = "SELECT faction_id " .
			"FROM faction_member " .
			"WHERE ruler_id = " . $_SESSION[ 'ruler_id' ] . " AND requested = 0 AND invited = 0";
	$result = mysql_query( $query ) or die( "Query failed : " . mysql_error() );
	$row = mysql_fetch_array($result, MYSQL_ASSOC);
	if( isset( $row[ 'faction_id' ] ) ) {
		$query = "SELECT score " .
				"FROM faction " .
				"WHERE faction_id = " . $row[ 'faction_id' ];
		$result = mysql_query( $query ) or die( "Query failed : " . mysql_error() );
		$row = mysql_fetch_array($result, MYSQL_ASSOC);
		$score = $row[ 'score' ];
		
		$query = "SELECT count(*) " .
				"FROM ruler " .
				"WHERE score > $score";
		$result = mysql_query( $query ) or die( "Query failed : " . mysql_error() );
		$row = mysql_fetch_array($result, MYSQL_ASSOC);
		$rank = $row[ 'count(*)' ];
		
		$rank -= 4;
		if( $rank < 0 ) {
			$rank = 0;
		}		
	}
	else {
		$rank = 0;
	}
	$query = "SELECT * " .
			"FROM faction " .
			"ORDER BY score DESC " .
			"LIMIT $rank, 8";
	$result = mysql_query( $query ) or die( "Query failed : " . mysql_error() );
	$num = mysql_numrows( $result );
	$i = 0;
	$response[0] = new StdClass();
	$response[0]->title = "Factions";
	$response[0]->data = Array();
	while ( $i < $num ) {
		$data = new stdClass();
		$data->name = mysql_result( $result, $i, "name" );
		$data->score = mysql_result( $result, $i, "score" );
		$query2 = "SELECT SUM(experience) " .
				"FROM ruler " .
				"JOIN faction_member ON faction_member.ruler_id = ruler.ruler_id " .
				"WHERE faction_id = " . mysql_result( $result, $i, "faction_id" ) . " AND requested = 0 AND invited = 0";
		$result2 = mysql_query( $query2 ) or die( "Query failed : " . mysql_error() );
		$row2 = mysql_fetch_array($result2, MYSQL_ASSOC);
		$experience = $row2[ 'SUM(experience)' ];		
		$data->experience = $experience;
		$response[0]->data[] = $data;
		$i ++;
	}
	$response[0]->responseSchema->fields = Array( 'name', 'score', 'experience' );
	$options->series = Array();
	$series = new stdClass();
	$series->yField = 'score';
	$series->displayName = 'Score';
	$series->style->color = '0x0F780F';
	$series->style->size = 10;
	$options->series[] = $series;
	$series = new stdClass();
	$series->yField = 'experience';
	$series->displayName = 'Battle score';
	$series->style->color = '0xC83C28';
	$series->style->size = 10;
	$options->series[] = $series;
	
	$options->xField = 'name';
	$options->yAxis = "numberAxis";
	$options->dataTipFunction = "getDataTipTextColumn";
	$options->expressInstall = "assets/expressinstall.swf";
	$options->style = $style; 
	$response[0]->options = $options;
	$response[0]->chartType = 'column';
}
elseif( $tab == 'armies' ) {
	$query = "SELECT * " .
			"FROM army " .
			"WHERE ruler_id = " . $_SESSION[ 'ruler_id' ] . " " .
			"ORDER BY ( scout * 14 + infantry * 48 + cavalry * 256 + artillery * 400 ) DESC " .
			"LIMIT 0, 8";
	$result = mysql_query( $query ) or die( "Query failed : " . mysql_error() );
	$num = mysql_numrows( $result );
	$i = 0;
	$response[0] = new StdClass();
	$response[0]->title = "Army composition";
	$response[0]->data = Array();
	while ( $i < $num ) {
		$data = new stdClass();
		$data->name = mysql_result( $result, $i, "name" );
		$data->scouts = mysql_result( $result, $i, "scout" );
		$data->infantry = mysql_result( $result, $i, "infantry" );
		$data->cavalry = mysql_result( $result, $i, "cavalry" );
		$data->artillery = mysql_result( $result, $i, "artillery" );
		$response[0]->data[] = $data;
		$i ++;
	}
	$response[0]->responseSchema->fields = Array( 'name', 'scouts', 'infantry', 'cavalry', 'artillery' );
	$options->series = Array();
	$series = new stdClass();
	$series->yField = 'scouts';
	$series->displayName = 'Scouts';
	$series->style->size = 10;
	$options->series[] = $series;
	$series = new stdClass();
	$series->yField = 'infantry';
	$series->displayName = 'Infantry';
	$series->style->size = 10;
	$options->series[] = $series;
	$series = new stdClass();
	$series->yField = 'cavalry';
	$series->displayName = 'Cavalry';
	$series->style->size = 10;
	$options->series[] = $series;
	$series = new stdClass();
	$series->yField = 'artillery';
	$series->displayName = 'Artillery';
	$series->style->size = 10;
	$options->series[] = $series;
	
	$options->xField = 'name';
	$options->yAxis = "numberAxis";
	$options->dataTipFunction = "getDataTipTextColumn";
	$options->expressInstall = "assets/expressinstall.swf";
	$options->style = $style; 
	$response[0]->options = $options;
	$response[0]->chartType = 'column';
}
elseif( $tab == 'trade' ) {
    $turn = getCurrentTurn();
	$query2 = "SELECT turns_inactive " .
			"FROM game";
	$result2 = mysql_query( $query2 ) or die( "Query failed : " . mysql_error() );
	$row2 = mysql_fetch_array($result2, MYSQL_ASSOC);
    $turns_inactive = $row2[ 'turns_inactive' ];
    $query = "SELECT * " .
    		"FROM trade_value " .
    		"WHERE turn > " . ( $game_turn - $turns_inactive ) . " " .
    		"ORDER BY turn ASC";
    $result = mysql_query( $query ) or die( "Query failed : " . mysql_error() );
    $num = mysql_numrows( $result );
    $steps = $turns_inactive / 60;
	$i = 0;
	$response[0] = new StdClass();
	$response[0]->title = "Trade history";
	$response[0]->data = Array();
	$last_iron_gold = 0;
	$last_coal_gold = 0;
	$count = 61;
	while ( $i < $num ) {
		$trade_turn = $turn - mysql_result( $result, $i, "turn" );
        if( $trade_turn / $steps < $count ) {
	        if( $trade_turn == 0 ) {
	        	$trade_turn = "Yesterday";
	        }
	        else {
	        	$trade_turn = ( $trade_turn + 1 ) . " days ago";
	        }
			$data = new stdClass();
			$data->turn = $trade_turn;
			if( mysql_result( $result, $i, "iron_gold" ) != 0 ) {
				$last_iron_gold = $data->iron_gold = mysql_result( $result, $i, "iron_gold" );
			}
			else {
				$data->iron_gold = $last_iron_gold;
			}
			if( mysql_result( $result, $i, "coal_gold" ) != 0 ) {
				$last_coal_gold = $data->coal_gold = mysql_result( $result, $i, "coal_gold" );
			}
			else {
				$data->coal_gold = $last_coal_gold;
			}
			$data->gold = 1;
			$response[0]->data[] = $data;
			$count --;
        }
		$i ++;
	}
	$response[0]->responseSchema->fields = Array( 'turn', 'iron_gold', 'coal_gold', 'gold' );
	$options->series = Array();
	$series = new stdClass();
	$series->yField = 'iron_gold';
	$series->displayName = 'Iron for gold';
	$series->style->color = '0xC83C28';
	$options->series[] = $series;
	$series = new stdClass();
	$series->yField = 'coal_gold';
	$series->displayName = 'Coal gold';
	$series->style->color = '0x2D2D2D';
	$options->series[] = $series;
	$series = new stdClass();
	$series->yField = 'gold';
	$series->displayName = 'Gold for gold';
	$series->style->color = '0x96500A';
	$options->series[] = $series;
	
	$options->xField = 'turn';
	//$options->yAxis = "lowNumberAxis";
	$options->dataTipFunction = "getDataTipTextLine";
	$options->expressInstall = "assets/expressinstall.swf";
	$options->style = $style; 
	$response[0]->options = $options;
	$response[0]->chartType = 'line';
}
/*elseif( $tab == 'news' ) {
	
}
elseif( $tab == 'upgrades' ) {
	
}*/

print( $json->encode( $response ) );
?>
